<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>项目建设阶段、目标及资金使用计划</title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>

<style type="text/css">
	.input_width { width:130px }
	.select_width { width:143px }
	.table_td td {border:0}
	.long_input{ width:642px }
    .selectWidth4{width:616px;}
    .table_tmp {  border-collapse:collapse;/*细线表格代码*/ }
	.table_tmp td { border:1px solid #b7d1e6;/*细线表格线条颜色*/ padding:4px; }
	.table_tmp th { border:1px solid #b7d1e6; font-weight:bold; text-align:center; background:#edf2f8; padding:4px; }
</style>
<script type="text/javascript">
var type = "${param.type}";
var parentTable = parent.$("#"+"${param.parentTab}");	//父页面的表格
var selectRadio = $();									//父页面选中的单选框
var selectTr = $();										//父页面选中的行



if(type=="investmented") {
	selectRadio = parent.$("#investmented_equipments");
	selectTr = selectRadio.parents("td");
}

if(type=="new_investment") {
	selectRadio = parentTable.find("#new_equipments_costs_0");
	selectTr = selectRadio.parents("td");
}

$(function(){
	
	$("input:not(:button)").each(function(){
		var id=$(this).attr("name");
		if(id==null || id=="")
			return true;
		var parentObj=selectTr.find("[name$='/"+id+"']");
		var value="";
		value=parentObj.val();
		$(this).val(value);
	});
	
	initTblEquipments();
	
	$("#savePsn").click(function(){
		setTimeout(savePsn,100);
		
		
	
	});
});

function countParentFund(){
	parentTable.find("#investmented_costs_3").click();
}

	function initTblEquipments(){
		var xmlStr = $("#equipments").val();
		var reg = /[\r\n]/g;
		xmlStr=xmlStr.replace(reg,""); 
		if(xmlStr==null || xmlStr=="")
			return false;
		var equipmentNode = /<equipment[^s](.\n?)+?<\/equipment>/g;
		var equipment = xmlStr.match(equipmentNode);
		if(equipment != null){
			
			for(var i=0; i<equipment.length; i++){
				$("#cmdAddbefore").click();
				equipment[i] = equipment[i].replace(reg,"");
				var j = i + 1;
				
				var cname = equipment[i].match(/<cname(.\n?)+?<\/cname>/);
				if(cname != null){
					cname = cname[0].replace(/<cname.*?>|<\/cname>/g,"");
					$("#equipment" + j +"_cname").val(cname);
				}
				var model = equipment[i].match(/<model(.\n?)+?<\/model>/);
				if(model != null){
					model = model[0].replace(/<model.*?>|<\/model>/g,"");
					$("#equipment" + j +"_model").val(model);
				}
				var standard = equipment[i].match(/<standard(.\n?)+?<\/standard>/);
				if(standard != null){
					standard = standard[0].replace(/<standard.*?>|<\/standard>/g,"");
					$("#equipment" + j +"_standard").val(standard);
				}
				var amount = equipment[i].match(/<amount(.\n?)+?<\/amount>/);
				if(amount != null){
					amount = amount[0].replace(/<amount.*?>|<\/amount>/g,"");
					$("#equipment" + j +"_amount").val(amount);
				}
				var price = equipment[i].match(/<price(.\n?)+?<\/price>/);
				if(price != null){
					price = price[0].replace(/<price.*?>|<\/price>/g,"");
					$("#equipments_costs_" + j).val(price);
				}
			}
		}
	}
	
	function savePsn(){
		validateByTabRow($("#tblEquipments"),"仪器设备详情",1);
		if(!valResult()){
			irisValShowMsg($("#savePsn"));
			return false;
		}
		
		var xmldate = prePareXmlDataStand($("#tblEquipments"), "", "");
		$("#equipments").val(xmldate.replace(/<equipments.*?>|<\/equipments>/g,""));
		
		$("#equipments,#equipments_costs_0").each(function(){
			
			var id=$(this).attr("name");
			var parentObj=null;
			
			if(id==null || id=="")
				return true;
			
			//获得父页面的对象
			
			parentObj=selectTr.find("[name$='/"+id+"']");
			
			if(parentObj!=null){
				parentObj.val($(this).val());
			}
			
		});
		
		$(".wBox_popup").hide();
		if(confirm("保存成功，是否返回申请书页面")){
			parent.tb_remove();
			parentTable.find("#investmented_costs_3").click();
		}
	}
	


function loadAjaxSelect(selectId,url,params,varParm){
	$.ajax( {
		url : url,
		type : 'post',
		dataType:'json',
		data : params,
		success : function(data) {
			
			for(var i=0;i<data.length;i++){
				var value=data[i].id;
				var text=data[i].name;		
				$("#"+selectId).append("<option value='"+value+"'>"+text+"</option>");
				

			}
			if(type=="edit"){//如果是修改，才需要初始化select框的值
				var selectValue=$("[name='"+selectId+"_value']").val();
				$("#"+selectId+" option").each(function(i,obj){
					if($(obj).val()==selectValue){
						setTimeout(function() {
							$(obj).attr("selected",true);
						}, 1);
					}
				});
			}
			
				
		}
	});
	}


</script>

</head>
<body>

	<div id="tabnav">
		<ul>
			<li class="down" id="tab1" onclick="changeTab(this.id)">
					<a href="###"><span>仪器设备详情</span></a>
			</li>
		</ul>
	</div>
	
	<div class="tab_box" id="fragment-tab1">
		
	<input type="hidden" id="equipments" name="equipments" >
	<input type="hidden" id="equipments_costs_0" name="equipments/total_costs" value="">
	<table  id="tblEquipments" cellpadding="0" class="table_tmp" width="735px" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<thead>
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center"  width="35px">选择</th>
						<th class="TblHead" align="center"  width="35px">序号</th>
						<th class="TblHead" align="center"  width="150px">设备名称</th>
						<th class="TblHead" align="center"  width="150px">型号</th>
						<th class="TblHead" align="center"  width="150px">规格</th> 
						<th class="TblHead" align="center"  width="100px">数量</th> 
						<th class="TblHead" align="center"  width="100px">价格（万元）</th> 
					</tr>
			</thead>
			<tbody id="tab">
					<tr  style="display:none">
						<td align="center">&nbsp;
							<input type="radio" class="radiobutton" name="selEquipmentList1" >
						</td>
						<td align="center">&nbsp;
							<span name="equipments|equipment[0]@seq_no" >[index]</span> 
						</td>
						<td>
							<input type="text" name="equipments|equipment[0]|cname" label="名称" id="equipment[index]_cname" style="width:120px;" class="required input_text maxlength:50" maxlength="50"/>
						</td>
						<td>
							<input type="text" name="equipments|equipment[0]|model" label="型号" id="equipment[index]_model" style="width:120px;" class="required input_text maxlength:50" maxlength="50"/>
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|standard" label="规格" id="equipment[index]_standard" style="width:120px;" class="required input_text maxlength:50" maxlength="50"/>
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|amount" label="数量"  id="equipment[index]_amount" onfocus="InitInput.setNumber(this,7,0,0)" style="text-align:right;width:60px;" class="required input_text maxlength:50" maxlength="50"/>
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|price" id="equipments_costs_[index]" onchange="countFund('equipments_costs_','1,2,3,4,5,6,7,8,9,10,11,12,13,14,15','0');" label="价格" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:60px;" class="required input_text input_costs maxlength:50" maxlength="50"/>
						</td> 
					</tr>
				
				</tbody>
			</table>
			<br>
			<table>
			  <tr >
				<td colspan="6">
					<input class="button" name="cmdAddbefore" type=button value="添加" id="cmdAddbefore"
						onclick="if(checkTabLimit('tblEquipments',15,'仪器设备最多只能填写15条')){addNewRow('tblEquipments');showDateTag('tblEquipments');}try{top.resizeFrame();}catch(e){};">
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblEquipments','selEquipmentList1')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblEquipments','selEquipmentList1')">
					<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow('tblEquipments','仪器设备详情');countFund('equipments_costs_','1,2,3,4,5,6,7,8,9,10,11,12,13,14,15','0');countParentFund();">
				</td>
				</tr>
			</table>
			
			<br>
			<table width="100%" align="center">
				<tr>
					<td><input type="button"  class="button_01 notdisabled" id="savePsn" value="保存">
						&nbsp;<input type="button" id="cancel" class="button_01 notdisabled" value="取消" onclick="parent.tb_remove();">
					</td>
				</tr>
			</table>
			
	</div>
</body>
</html>